<template>
  <el-card shadow="never">
    <template #header>
      <el-form label-width="80px">
        <el-row :gutter="24">
          <el-col :span="6" :xs="24">
            <el-form-item label="贷超APP">
              <el-select v-model="page.appId" style="width: 100%" clearable>
                <el-option v-for="item in productList" :key="item.appId" :label="item.appName"
                           :value="item.appId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10" :xs="24">
            <el-form-item label="日期">
              <el-date-picker
                  style="width: 100%"
                  v-model="page.createTimeValue"
                  type="daterange"
                  range-separator="~"
                  value-format="x"
                  start-placeholder="开始时间"
                  end-placeholder="结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6" :xs="24">
            <el-form-item label-width="20px">
              <el-button type="primary" @click="getTableData">查询</el-button>
              <el-button @click="resetSearch">重置</el-button>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
    </template>
    <Table :tableData="tableData" :tableColumn="tableColumn" :page="page"
           @handleCurrentChange="(val)=>{page.pageNum = val,getTableData()}"
           @handleSizeChange="(val)=>{page.pageSize = val,getTableData()}"
    >
    </Table>
  </el-card>
</template>

<script>
import {defineComponent, onMounted, reactive, ref, toRefs,} from 'vue'
import {fetchUserReport} from '@/api/report'
import {dateFormatTimeStamp} from "@/utils";
import {selectProductList} from "@/api";

const tableColumn = [
  {label: '贷超APP', prop: 'appName', align: 'center'},
  {label: '日期', prop: 'date', align: 'center', minWidth: 150},
  {label: '安装数', prop: 'installNum', align: 'center'},
  {label: '注册数', prop: 'registerNum', align: 'center'},
  {label: '注册率', prop: 'registerPercentStr', align: 'center'},
  {label: '登录人数', prop: 'loginNum', align: 'center'},
  {label: '注册申请人数', prop: 'applyNum', align: 'center'},
  {label: '注册申请率', prop: 'applyPercentStr', align: 'center'},
  {label: '注册申请总笔数', prop: 'applyCount', align: 'center'},
  {label: '注册申请者人均申请笔数', prop: 'applyAverage', align: 'center'},
  {label: '当日申请人数', prop: 'applyNow', align: 'center'},
  {label: '当日申请率', prop: 'applyNowPercentStr', align: 'center'},
  {label: '当日申请总笔数', prop: 'applyNowCount', align: 'center'},
  {label: '当日人均申请笔数', prop: 'applyNowAverage', align: 'center'},
  {label: '当日活跃人数', prop: 'activeNum', align: 'center'},
  {label: '当日打开APP总次数', prop: 'openCount', align: 'center'},
  {label: '人均当日打开APP次数', prop: 'openAverage', align: 'center'},

]
export default {
  name: "userStatisticsReport",
  setup() {
    const state = reactive({
      page: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      productList: [],
      tableData: []
    })
    const methods = {
      async getTableData() {
        const [startTime, endTime] = dateFormatTimeStamp(state.page.createTimeValue)
        const params = {
          startTime, endTime,
          ...state.page,
          createTimeValue: null
        }
        const res = await fetchUserReport(params)
        if (res.code === 200) {
          const {list, total} = res.data
          state.tableData = list
          state.page.total = total
        }
      },
      getSelect() {
        selectProductList({status: 1}).then(res => {
          state.productList = res.data
        })
      },
      resetSearch() {
        state.page = {
          pageNum: 1,
          pageSize: 10,
          total: 0
        }
        methods.getTableData()
      }
    }
    onMounted(() => {
      methods.getTableData()
      methods.getSelect()
    })
    return {
      ...methods,
      ...toRefs(state),
      tableColumn
    }
  }
}
</script>

<style scoped>

</style>
